package com.baohulu.baohulu.activity.account;

import java.util.regex.Pattern;

abstract class AccountState {
    AccountActivity mActivity;
    String phoneNumber;
    String password;

    AccountState(AccountActivity activity) {
        mActivity = activity;
        init();
    }

    abstract void init();//初始化界面和数据

    void resolveInput() {//处理用户输入数据
        if (isInputLegal()) {
            submitData();
        }
    }

    protected abstract boolean isInputLegal();//检查用户输入是否合法

    protected abstract void submitData();//向服务器提交数据

    /**
     * 忘记密码，登录状态需要处理
     */
    void forgetPassword() {}

    boolean isPhoneNumberInvalid(String phoneNumber) {
        Pattern pattern = Pattern.compile("^(1[34578]\\d)\\d{8}$");
        return !pattern.matcher(phoneNumber).matches();
    }
}
